package com.lqw.vhr.controller.personnel;

import com.lqw.vhr.model.*;
import com.lqw.vhr.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnel")
public class PersonnelController {
    @Autowired
    EmployEcService employEcService;

    @Autowired
    DepartmentService departmentService;

    @Autowired
    EmployeeService employeeService;

    @Autowired
    EmployTrainService employTrainService;

    @Autowired
    AdjustSalService adjustSalService;

    @Autowired
    EmpMoveService empMoveService;


    @Autowired
    PositionService positionService;

    @GetMapping("/ec/")
    public RespPageBean getEmpEcByPage(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer size,
                                       @RequestParam(required = false) String keyword) {
        return employEcService.getEmpEcByPage(page, size, keyword);
    }

    @PutMapping("/ec/")
    public RespBean updateEmpEc(@RequestBody EmployeeEc empEc) {
        if (employEcService.updateEmpEc(empEc) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PostMapping("/ec/")
    public RespBean addEmpEc(@RequestBody EmployeeEc empEc) {
        if (employEcService.addEmpEc(empEc) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @DeleteMapping("/ec/{id}")
    public RespBean deleteEmpByEid(@PathVariable Integer id) {
        if (employEcService.deleteEmpEcByEid(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @GetMapping("/ec/depts")
    public List<Department> getDepartments() {
        return departmentService.getAllDepartmentsWithOutChildren();
    }

    @GetMapping("/ec/emps")
    public List<Employee> getEmployee() {
        return (List<Employee>) employeeService.getEmployeeByPage(null, null, new Employee(), null).getData();
    }

    @GetMapping("/train/")
    public RespPageBean getEmpTrainByPage(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          @RequestParam(required = false) String keyword) {
        return employTrainService.getEmpTrainByPage(page, size, keyword);
    }

    @PutMapping("/train/")
    public RespBean updateEmpTrain(@RequestBody Employeetrain employeetrain) {
        if (employTrainService.updateEmpTrain(employeetrain) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PostMapping("/train/")
    public RespBean addEmpTrain(@RequestBody Employeetrain employeetrain) {
        if (employTrainService.addEmpTrain(employeetrain) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @DeleteMapping("/train/{id}")
    public RespBean deleteEmpTrainById(@PathVariable Integer id) {
        if (employTrainService.deleteEmpTrainById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
    @GetMapping("/train/emps")
    public List<Employee> getEmployeeWithEmpTrain() {
        return (List<Employee>) employeeService.getEmployeeByPage(null, null, new Employee(), null).getData();
    }

    @GetMapping("/salary/")
    public RespPageBean getAdjustSalByPage(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size,
                                           @RequestParam(required = false) String keyword) {
        return adjustSalService.getAdjustSalByPage(page, size, keyword);
    }

    @PutMapping("/salary/")
    public RespBean updateAdjustSal(@RequestBody AdjustSalary adjustSalary) {
        if (adjustSalService.updateAdjustSal(adjustSalary) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PostMapping("/salary/")
    public RespBean addAdjustSal(@RequestBody AdjustSalary adjustSalary) {
        if (adjustSalService.addAdjustSal(adjustSalary) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @DeleteMapping("/salary/{id}")
    public RespBean deleteAdjustById(@PathVariable Integer id) {
        if (adjustSalService.deleteAdjustById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @GetMapping("/salary/emps")
    public List<Employee> getEmployeesWithAdjustSal() {
        return (List<Employee>) employeeService.getEmployeeByPage(null, null, new Employee(), null).getData();
    }


    @GetMapping("/remove/")
    public RespPageBean getEmpRemoveByPage(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size,
                                           @RequestParam(required = false) String keyword) {
        return empMoveService.getEmpMoveByPage(page, size, keyword);
    }

    @PutMapping("/remove/")
    public RespBean updateEmpRemove(@RequestBody Employeeremove employeeremove) {
        if (empMoveService.updateEmpRemove(employeeremove) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PostMapping("/remove/")
    public RespBean addEmpRemove(@RequestBody Employeeremove employeeremove) {
        if (empMoveService.addEmpRemove(employeeremove) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @DeleteMapping("/remove/{id}")
    public RespBean deleteEmpRemoveById(@PathVariable Integer id) {
        if (empMoveService.deleteEmpRemoveById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @GetMapping("/remove/emps")
    public List<Employee> getEmployeesWithEmpRemove() {
        return (List<Employee>) employeeService.getEmployeeByPage(null, null, new Employee(), null).getData();
    }

    @GetMapping("/remove/deps")
    public List<Department> getDeptsWithEmpRemove() {
        return departmentService.getAllDepartmentsWithOutChildren();
    }

    @GetMapping("/remove/positions")
    public List<Position> getJobLevelsWithEmpRemove() {
        return positionService.getAllPositions();
    }

}
